package board;

/**
 * @author tymoshya
 * @since 8/5/11
 */
public abstract class Board implements IBoard {
    private int height;
    private int width;
    private int[][] battlefield;

    protected Board(int height, int width) {
        this.height = height;
        this.width = width;
        initBattlefield();
    }


    public boolean isReady() {
        // TODO true if proper number of all kind of ships is  placed
        return false;
    }

    @Override
    public String toString() {
        final String SPACE = "  ";
        final String[] LETTERS = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
        StringBuilder sb = new StringBuilder();

        sb.append("\n\n\n");
        // header
        sb.append(" ");
        for (int w = 0; w < width; w++) {
            sb.append(SPACE);
            sb.append(w);
        }
        sb.append("\n");
        // field and left columnTitle
        for (int v = 0; v < height; v++) {
            sb.append(LETTERS[v]);
            sb.append(SPACE);
            for (int h = 0; h < width; h++) {
                sb.append(battlefield[v][h]);
                sb.append(SPACE);
            }
            sb.append("\n");
        }

        return sb.toString();
    }

    public int[][] getBattleField() {
        return battlefield;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    private void initBattlefield() {
        battlefield = new int[height][width];

        for (int h = 0; h < height; h++)
            for (int w = 0; w < width; w++)
                battlefield[h][w] = Coordinate.Status.FREE;
    }
}
